{extend name="public:layout" /}
{block name="title"}商品管理{/block}
{block name="head"}
<style>
    i{cursor:pointer}
</style>
{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> 商品列表</li>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="toolbar">
                <div class="pull-left">
                    <form class="form-inline" method="post" id="searchForm">
                        <input type="hidden" name="cid" />
                        <div class="form-group">
                            <select id="locatlCid" class="form-control">
                                <option>==商品类目==</option>
                                {volist name="category" id="vo"}
                                <option value="{$vo.cid}" {eq name="query.cid" value="$vo['cid']"}selected{/eq}>{$vo._name}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="form-group">
                            <select name="is_on_sale" class="form-control">
                                <option value="-2">商品状态</option>
                                <option value="1" {eq name="query.is_on_sale" value="1"}selected{/eq}>正常销售</option>
                                <option value="0" {eq name="query.is_on_sale" value="0"}selected{/eq}>店铺下架</option>
                                <option value="10" {eq name="query.is_on_sale" value="10"}selected{/eq}>违规下架</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>店铺名称</label>
                            <input class="form-control" name="site_name" value="{$query.site_name}" type="text" placeholder="店铺名称">
                        </div>
                        <div class="form-group">
                            <label>商品名称</label>
                            <input class="form-control" name="goods_name" value="{$query.goods_name}" type="text" placeholder="">
                        </div>
                        <button type="submit" class="btn btn-info">
                            <i class="fa fa-search"></i> 搜索
                        </button>
                        <a class="btn btn-white" href="{:url('index')}">
                            <i class="fa fa-trash"></i> 清空
                        </a>
                    </form>
                </div>
                <div class="pull-right">
                    <button class="btn btn-white" type="button"
                            onclick="updateOrder()">
                        <i class="fa fa-sort"></i>更新排序
                    </button>
                </div>
                <div class="clearfix"></div>
            </div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="50">#</th>
                    <th>排序</th>
                    <th>商品名称</th>
                    <th width="120">类目</th>
                    <th width="120">商品状态</th>
                    <th width="120">操作</th>
                </tr>
                </thead>
                <tbody>
                {volist name="list" id="vo"}
                <tr>
                    <td>{$vo.goods_id}</td>
                    <td width="80"> <input type="text" class="form-control list_order"
                                name="list_order[{$vo.goods_id}][goods_sort]" value="{$vo['goods_sort']}"/>
                    </td>
                    <td>
                        <img src="{$vo.goods_thumb|default='/public/nopic.gif'}" class="pull-left" style="width:32px;height:32px;margin:4px;" />
                                {$vo.goods_name}<br/>
                        <small class="text-warning">店铺：{$vo.site_name}</small>
                    </td>
                    <td>{$category[$vo['cid']]['cat_name']}</td>
                    <td>
                        {eq name="vo.is_on_sale" value="0"}已下架{/eq}
                        {eq name="vo.is_on_sale" value="1"}出售中{/eq}
                        {eq name="vo.is_on_sale" value="10"}
                        <a class="text-danger" data-toggle="popover" data-placement="left" title="违规下架原因" data-content="{$vo.sale_remark}">
                            违规下架
                        </a>
                        {/eq}
                    </td>
                    <td>
                        {neq name="vo.is_on_sale" value="10"}
                        <a href="javascript:;" onclick="soldOut('{$vo.goods_id}');">违规下架</a>
                        {else/}
                        <a href="javascript:;" onclick="doAction(this);"
                           data-msg="确认上架吗？" data-url="{:url('soldUp')}" data-params="goods_id={$vo.goods_id}">上架</a>
                        <a href="javascript:;" onclick="doAction(this);"
                           data-msg="确认删除吗？" data-url="{:url('del')}" data-params="goods_id={$vo.goods_id}">删除</a>
                        {/neq}
                    </td>
                </tr>
                {/volist}
                </tbody>
            </table>
            <div class="page-bar">{$list->render()}</div>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        $('#locatlCid').change(function () {
            var cid=$(this).val();
            $("input[name='cid']").val(cid);
            $('#searchForm').submit();
        });
        $('[data-toggle="popover"]').popover();
    });
    //违规下架
    function soldOut(goodsId) {
        In('layer',function () {
            layer.prompt({
                formType: 2,
                title: '请输入违规下架原因',
                area: ['300px', '80px'] //自定义文本域宽高
            }, function(value, index, elem){
                var url="{:url('soldOut')}";
                layer.close(index);
                $.post(url,{goods_id:goodsId,sale_remark:value},function (res) {
                    if(res.code==1){
                        layer.msg(res.msg, {icon: 1, time: 800}, function () {
                            rePage();
                        });
                    }else{
                        layer.alert(res.msg);
                    }
                });
            });
        })
    }
    //更新排序
    function updateOrder() {
        if ($(".list_order").length > 0) {
            var data = $(".list_order").serialize();
            var url = "{:url('updateOrder')}";
            getAjax(url, data, function (data) {
                layer.msg(data.msg, {icon: 1, time: 800}, function () {
                    rePage();
                });
            });
        }
    }
</script>
{/block}